import jsonp from 'jsonp';

export const requestJsonp = (url, params) => {
	console.log(url, params)
  return new Promise((resolve, reject) => {
    // 拼接URL参数
    const query = Object.keys(params)
      .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
      .join('&');
    const fullUrl = url + (url.includes('?') ? '&' : '?') + query;

    // 发起JSONP请求
    jsonp(fullUrl, { param: 'callback' }, (err, data) => {
      if (err) reject(err);
      else resolve(data);
    });
  });
};